package com.tanglongan.designPattern.dp01_factoryMethod.demo99;

public class GenericClient {

    /**
     * 调用客户端
     */
    public static void main(String[] args) {
        IFactory factoryA = new FactoryA();
        factoryA.makeProduct().doSomething();

        IFactory factoryB = new FactoryB();
        factoryB.makeProduct().doSomething();

        IFactory factoryC = new FactoryC();
        factoryC.makeProduct().doSomething();
    }

    /**
     * 抽象产品
     */
    public interface IProduct {
        void doSomething();
    }

    /**
     * 产品A
     */
    static class ProductA implements IProduct {
        @Override
        public void doSomething() {
            System.out.println("I am a ProductA");
        }
    }

    /**
     * 产品B
     */
    static class ProductB implements IProduct {
        @Override
        public void doSomething() {
            System.out.println("I am a ProductB");
        }
    }

    /**
     * 产品C
     */
    static class ProductC implements IProduct {
        @Override
        public void doSomething() {
            System.out.println("I am a ProductC");
        }
    }

    /**
     * 抽象工厂
     */
    public interface IFactory {
        IProduct makeProduct();
    }

    /**
     * 生成ProductA的具体工厂
     */
    static class FactoryA implements IFactory {
        @Override
        public IProduct makeProduct() {
            return new ProductA();
        }
    }

    /**
     * 生成ProductB的具体工厂
     */
    static class FactoryB implements IFactory {
        @Override
        public IProduct makeProduct() {
            return new ProductB();
        }
    }

    /**
     * 生成ProductC的具体工厂
     */
    static class FactoryC implements IFactory {
        @Override
        public IProduct makeProduct() {
            return new ProductC();
        }
    }
}
